﻿using System;
using System.Web;
using System.Web.UI;
using System.Linq;
using Models;


public partial class PhotoAdd : AdminBase
{
    public int _Id = 0;

    protected void Page_Load(object sender, EventArgs e)
    {

        Response.CacheControl = "no-cache";
        if (!string.IsNullOrEmpty(Request.Params["ID"]))
        {
            _Id = int.Parse(HttpContext.Current.Request.QueryString["ID"]);

        }

        if (!Page.IsPostBack)
        {

            if (_Id != 0)
            {
                ShowInfo(_Id);
            }

        }


    }

    //保存


    private void ShowInfo(int _id)
    {

        Entities mydb = new Entities();
        {

            Photo_Item _lt = mydb.Photo_Item.First(p => p.PID == _id);
            txtPname.Text = _lt.Pname;
            txtImgUrl.Text = _lt.Pimg;
            txtPcontent.Value = _lt.Pcontent;
            txtPcontent1.Value = _lt.Pcontent1;
            txtPrice.Text = _lt.Pprice.ToString();


        }
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Entities mydb = new Entities();
        {
            Photo_Item Lt = new Photo_Item();
            if (_Id != 0)
                Lt = mydb.Photo_Item.First(p => p.PID == _Id);
            Lt.Pimg = txtImgUrl.Text.Trim();
            Lt.Pname = txtPname.Text.Trim();
            Lt.Pcontent = txtPcontent.Value;
            Lt.Pcontent1 = txtPcontent1.Value;
            Lt.Pprice = int.Parse(txtPrice.Text.Trim());

            if (_Id == 0)
            {
                mydb.Photo_Item.Add(Lt);
                mydb.SaveChanges();
                Response.Write("<script> var Close=1;</script>");
                // JscriptPrint("自定义标签添加成功啦！", "list.aspx", "Success");
            }
            else
            {
                mydb.SaveChanges();
                Response.Write("<script> var Close=1;</script>");

                // JscriptPrint("自定义标签修改成功啦！", "list.aspx", "Success");
            }
        }
    }
}

